package ar.edu.unq.tpi.uis.tepe3.dominio;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import ar.edu.unq.tpi.uis.tepe3.dominio.exception.UserCantBeCreated;
import ar.edu.unq.tpi.uis.tepe3.dominio.exception.UserCantBeDeleted;

/**
 * @author gpilla <gpilla@unq.edu.ar>
 *
 */
public class SvnManager implements Serializable{
	
	private List<User> users;
	private List<Group> groups;
	private Folder fileSystem;
	
	/**
	 * @throws SameFolderNameException 
	 * 
	 */
	public SvnManager() {
		this.users = new ArrayList<User>();
		this.groups = new ArrayList<Group>();
		this.fileSystem = new Folder("Root");
	}
	
	/**
	 * @return
	 */
	public List<User> getUsers() {
		return users;
	}

	/**
	 * @param users
	 */
	public void setUsers(List<User> users) {
		this.users = users;
	}

	/**
	 * @return
	 */
	public List<Group> getGroups() {
		return groups;
	}

	/**
	 * @param groups
	 */
	public void setGroups(List<Group> groups) {
		this.groups = groups;
	}
	
	/**
	 * @param group
	 */
	public void addGroup(Group group){
		this.groups.add(group);
	}

	/**
	 * @return
	 */
	public Folder getFileSystem() {
		return fileSystem;
	}

	/**
	 * @param fileSystem
	 */
	public void setFileSystem(Folder fileSystem) {
		this.fileSystem = fileSystem;
	}

	/**
	 * @param aNewUser
	 * @throws UserCantBeCreated
	 */
	public void addUser(User aNewUser) throws UserCantBeCreated {
		for (User aUser : this.users) {
			if(aUser.getId() == aNewUser.getId()){
				throw new UserCantBeCreated();
			}
		}
		this.getUsers().add(aNewUser);
		
	}
	
	/**
	 * @todo Agregar logica de cuando no podria ser borrado.
	 * @param aUser
	 * @throws UserCantBeDeleted
	 */
	public void removeUser(User aUser) throws UserCantBeDeleted{
		this.getUsers().remove(aUser); 
	}

	/**
	 * @return
	 */
	public int getNoOfUsers() {
		return this.getUsers().size();
	}

	/**
	 * @param aGroup
	 */
	public void removeGroup(Group aGroup) {
		this.getGroups().remove(aGroup);
	}

	
}